import ResMgr  from "./ResMgr";
import PanelManager from "./PanelManager";
const {ccclass, property} = cc._decorator;

export default class SceneManager extends cc.Component {

    private static Instance: SceneManager = null;
    private scene_map:any = {};

    onLoad () 
    {
        SceneManager.Instance = this;
    }

    public static getInstace()
    {
        return SceneManager.Instance;
    }

    public change_scene(scene_name)
    {
        this.clearAllScene();
        PanelManager.getInstace().removeAllPanel();
        var parent = cc.find("Canvas").getChildByName("scene");
        var prefab = ResMgr.Instance.getAsset("Scenes", scene_name);
        var item = null;
        if (prefab) 
        {
            item = cc.instantiate(prefab);
            parent.addChild(item);
        }
        this.scene_map[scene_name] = item;
        return item;
    }

    public clearAllScene()
    {
        for (var key in this.scene_map) {
            if (this.scene_map[key]) {
                this.scene_map[key].removeFromParent();
                this.scene_map[key] = null;
            }
        }
    }

    public clear_scene(ui_name) 
    {
        if (this.scene_map[ui_name]) {
            this.scene_map[ui_name].removeFromParent();
            this.scene_map[ui_name] = null;
        }
    }



    start () {

    }

    // update (dt) {}
}
